package cn.yuhh.api.v1.declare;

import cn.yuhh.api.helper.ApiResponse;
import cn.yuhh.api.helper.IDataToMap;
import cn.yuhh.api.service.AbstractApiService;
import cn.yuhh.core.domain.DeclareInfo;
import com.magic.spring.mongo.Mongo;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component("userListDeclareService1.0")
public class UserListDeclareService extends AbstractApiService {
    @Override
    public Map service(Map request) {
        //根据ID查用户
        List<DeclareInfo> declareInfos = Mongo.buildMongo().eq("userId",selfId(request)).find(DeclareInfo.class);

        return ApiResponse.success(declareInfos, new IDataToMap<DeclareInfo>() {
            @Override
            public void dataToMap(Map map, DeclareInfo source) {
                map.put("selfId", selfId(request));
                source.list(map);
            }
        });
    }
}
